package cn.edu.hhu.servlet.student;

import cn.edu.hhu.Bean.Course;
import cn.edu.hhu.Bean.Student;
import cn.edu.hhu.service.Impl.StudentServiceImpl;
import cn.edu.hhu.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @anthor: lddd
 * @date: 2020/5/9 - 22:33
 * @description:
 **/
@WebServlet("/student/queryCourseServlet")
public class QueryCourseServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1取出session中的登录信息
        Student loginStudent = (Student)request.getSession().getAttribute("loginStudent");
        //2查询课程
        StudentService studentService = new StudentServiceImpl();
        List<Course> list = studentService.queryAllCourses(loginStudent);
        //3存储转发
        request.setAttribute("myCourses",list);
        request.getRequestDispatcher("/student/myCourse.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
